package org.mullin.stratego.shared;

public class Coord {			
	/** x and y points of a coordinate. */
	public int x, y;
	
	public Coord(int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	/**
	 * Manhattan distance between this coord and another.
	 * @param other
	 * @return
	 */
	public int distanceFrom(Coord other) {
		return Math.abs(x - other.x) + Math.abs(y - other.y);
	}
	
	@Override
	public boolean equals(Object rhs) {
		if (null == rhs)
			return false;
		if (!(rhs instanceof Coord))
			return false;
		Coord c = (Coord)rhs;
		return c.x == x && c.y == y;
	}
	
	@Override
	public String toString() {
		return new StringBuilder()
				.append("(")
				.append(x)
				.append(",")
				.append(y)
				.append(")")
				.toString();
	}
}
